
package net.com.hydroPK.net.packethandler;

import net.com.hydroPK.Engine;
import net.com.hydroPK.model.Player;
import net.com.hydroPK.util.Misc;
import net.com.hydroPK.GU;

public class PublicChat implements Packet {
    /**
     * Handles player chatting.
     * @param p The Player which the frame should be handled for.
     * @param packetId The packet id this belongs to.
     * @param packetSize The amount of bytes being recieved for this packet.
     */
    public void handlePacket(Player p, int packetId, int packetSize) {
        if (p == null || p.stream == null) {
            return;
        }
	if (p.muteType == 2) {
		p.message("you are muted");
	} else {
        int chatTextEffects = p.stream.readUnsignedWord();
        int numChars = p.stream.readUnsignedByte();
        String chatText = Misc.decryptPlayerChat(p.stream, numChars);
        if (chatText.startsWith("/")) {
            if (p.clanRoom.length() > 0) {
                Engine.clanChat.sendMessage(p, chatText.substring(1));
            }
        } else {
                p.chatTextEffects = chatTextEffects;
                p.chatText = chatText;
                p.chatTextUpdateReq = true;
                p.updateReq = true;
                if (p.toggleChat1) {
                    GU.logBox.append("\n"+p.username+": "+p.chatText);
		}
                p.appendData("logs/CharChatLogs/"+p.username+"2.txt","[" + Misc.getDate() + "]"+ p.username+": "+p.chatText);
                p.appendData("logs/ChatLog/chatlogs1.txt","[" + Misc.getDate() + "]"+ p.username+": "+p.chatText);
    }
    }
    }
}
